package org.september.pisces.filestore.aop;

import org.september.pisces.filestore.entity.FileStorePool;
import org.september.pisces.filestore.service.FileStorePoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class FileStoreWebMvcConfigurerAdapter implements WebMvcConfigurer, BeanPostProcessor {

    public ResourceHandlerRegistry resourceHandlerRegistry;
    
    @Autowired
    private FileStorePoolService fileStorePoolService;

	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//配置静态资源处理
		this.resourceHandlerRegistry = registry;
//		for(FileStorePool pool : fileStorePoolService.getAllPool()) {
//			registry.addResourceHandler("/file/"+pool.getPoolName()+"/**")
//	        .addResourceLocations("file:" + pool.getDiskPath())
//	        ;
//		}
	}
	
//	public void addResourceLocation(String poolName,String diskPath) {
//		if(!diskPath.endsWith("/")) {
//			diskPath += "/";
//		}
//		
//		resourceHandlerRegistry.addResourceHandler("/file/"+poolName+"/**")
//        	.addResourceLocations("file:" + diskPath);
//	}
	
//	public boolean hasMappingForPool(String poolName) {
//		return resourceHandlerRegistry.hasMappingForPattern("/file/"+poolName+"/**");
//	}
}
